//
//  ReportAlarmPointListCell.m
//  efairy
//
//  Created by 李锋 on 2019/3/14.
//  Copyright © 2019年 East. All rights reserved.
//

#import "ReportAlarmPointListCell.h"

@interface ReportAlarmPointListCell()

@end

@implementation ReportAlarmPointListCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}

-(void)initView{
    _titleView = [[UIView alloc]init];
    _titleView.backgroundColor  = ColorFromRGB(0xf2f2f4);
    
    _deviceType = [[UILabel alloc]init];//设备类型
    _deviceType.textColor = ColorFromRGB(0x333333);
    _deviceType.font = [UIFont systemFontOfSize:12.f];
    _deviceType.textAlignment = NSTextAlignmentLeft;
    
    _rows = [[UILabel alloc]init];//点位总数
    _rows.textColor = ColorFromRGB(0x333333);
    _rows.font = [UIFont systemFontOfSize:12.f];
    _rows.textAlignment = NSTextAlignmentCenter;
    
    _alarmRows = [[UILabel alloc]init];//报警点位数
    _alarmRows.textColor = ColorFromRGB(0xFF0000);
    _alarmRows.font = [UIFont systemFontOfSize:12.f];
    _alarmRows.textAlignment = NSTextAlignmentCenter;
    
    _waringRows = [[UILabel alloc]init];//预警点位数
    _waringRows.textColor = ColorFromRGB(0xFF7200);
    _waringRows.font = [UIFont systemFontOfSize:12.f];
    _waringRows.textAlignment = NSTextAlignmentCenter;
    
    _troubleRows = [[UILabel alloc]init];;//故障点位
    _troubleRows.textColor = ColorFromRGB(0xFFB900);
    _troubleRows.font = [UIFont systemFontOfSize:12.f];
    _troubleRows.textAlignment = NSTextAlignmentCenter;
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = ColorFromRGB(0xf2f2f4);
    
    [self.contentView sd_addSubviews:@[_titleView]];
    _titleView.sd_layout.heightIs(self.contentView.frame.size.height).rightSpaceToView(self.contentView, 0).leftSpaceToView(self.contentView, 0)
    .topSpaceToView(self.contentView, 0);
    [_titleView sd_addSubviews:@[_deviceType,_rows,_alarmRows,_waringRows,_troubleRows]];
    _troubleRows.sd_layout.leftSpaceToView(_waringRows, 0).heightIs(34).widthIs(48).rightSpaceToView(_titleView, 0);
    _waringRows.sd_layout.leftSpaceToView(_alarmRows, 0).heightIs(34).widthIs(48).rightSpaceToView(_troubleRows, 0);
    _alarmRows.sd_layout.leftSpaceToView(_rows, 0).heightIs(34).widthIs(48).rightSpaceToView(_waringRows, 0);
    _rows.sd_layout.leftSpaceToView(_deviceType, 0).heightIs(34).widthIs(48).rightSpaceToView(_alarmRows, 0);
    _deviceType.sd_layout.leftSpaceToView(_titleView, 4).rightSpaceToView(_rows, 0).topSpaceToView(_titleView, 11).autoHeightRatio(0).maxHeightIs(33);
    self.contentView.backgroundColor =ColorFromRGB(0xf2f2f4);
    [self setupAutoHeightWithBottomView:_titleView bottomMargin:0];
    
    
}



-(void)setDataModel:(DeviceStatisticsModel *)data{
    _deviceType.text = data.efairydevice_device_type;
    //调用
//    [self setLineSpace:2.0f withText:data.efairydevice_device_type inLabel:_deviceType];
    _rows.text = data.total_devices;
    _alarmRows.text = data.total_alarm_devices;
    _waringRows.text = data.total_early_warning_devices;
    _troubleRows.text = data.total_trouble_devices == nil ? @"0" :data.total_trouble_devices;
}


/**
 设置固定行间距文本
 
 @param lineSpace 行间距
 @param text 文本内容
 @param label 要设置的label
 */
-(void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{
    if (!text || !label) {
        return;
    }
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = lineSpace;  //设置行间距
    paragraphStyle.lineBreakMode = label.lineBreakMode;
    paragraphStyle.alignment = label.textAlignment;
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    label.attributedText = attributedString;
}

@end
